package com.dianhun.es.other;
/**
 * @author cyt
 * @create 2020-08-28 下午 5:31
 */
public class ss {

    public static void main(String[] args) {

    }

    public int minPathSum(int[][] grid) {
        // write code here
        int[][] ans = new int[grid.length][grid[0].length];
        for (int i = 0; i < grid.length; i++) {
            int text = i == 0 ? 0 : ans[i - 1][0];
            ans[i][0] = grid[i][0] + text;
        }
        for (int j = 0; j < grid[0].length; j++) {
            int text = j == 0 ? 0 : ans[0][j - 1];
            ans[0][j] = grid[0][j] + text;
        }
        for (int i = 1; i < grid.length; i++) {
            for (int j = 1; j < grid[0].length; j++) {
                int i_temp = grid[i][j] + ans[i - 1][j];
                int j_temp = grid[i][j] + ans[i][j - 1];
                ans[i][j] = i_temp > j_temp ? j_temp : i_temp;
            }
        }
        return ans[grid.length - 1][grid[0].length - 1];
    }
}
